package com.hspedu.newData.dmsxl.图;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-20 
 * @Version: 1.0
 */

public class LC797所有可能的路径 {

    List<List<Integer>> list= new ArrayList<>();
    List<Integer> path = new ArrayList<>();

    public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
        dfs(graph,0,graph.length - 1);
        return list;
    }

    public void dfs(int[][] graph,int x,int n){
        if (x==n){
            list.add(new ArrayList<>(path));
            return;
        }

        for(int y:graph[x]){
            path.add(y);
            dfs(graph,y,n);
            path.remove(path.size()-1);
        }
    }

}
